package com.imnc.eatmap.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.imnc.eatmap.R;
import com.imnc.eatmap.model.PoiInfoParcelable;
import com.imnc.eatmap.ui.base.BaseActivity;

public class PoiResultDetailActivity extends BaseActivity implements
		OnClickListener {

	private ActionBar mActionBar = null;
	private PoiInfoParcelable poiInfoParcelable = null;

	private TextView mNameTextView;
	private TextView mCityTextView;
	private TextView mAddressTextView;
	private TextView mPhoneNumTextView;
	private TextView mPostCodeTextView;
	private Button mGoingToButton;
	private Button mDetailButton;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_poi_result_detail);

		findView();
		initViews();
	}

	private void findView() {
		mNameTextView = (TextView) findViewById(R.id.txt_name);
		mAddressTextView = (TextView) findViewById(R.id.txt_address);
		mPhoneNumTextView = (TextView) findViewById(R.id.txt_phoneNum);
		mCityTextView = (TextView) findViewById(R.id.txt_city);
		mPostCodeTextView = (TextView) findViewById(R.id.txt_postCode);
		mGoingToButton = (Button) findViewById(R.id.btn_go);
		mDetailButton = (Button) findViewById(R.id.btn_detail);
	}

	private void initViews() {
		mActionBar = getSupportActionBar();
		mActionBar.setDisplayHomeAsUpEnabled(true);

		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		poiInfoParcelable = bundle.getParcelable("poiInfoParcelable");

		if (poiInfoParcelable == null) {
			defaultFinish();
		}

		mAddressTextView.setText(poiInfoParcelable.address);
		mCityTextView.setText(poiInfoParcelable.city);
		mPhoneNumTextView.setText(poiInfoParcelable.phoneNum);
		mPostCodeTextView.setText(poiInfoParcelable.postCode);
		mNameTextView.setText(poiInfoParcelable.name);

		mGoingToButton.setOnClickListener(this);
		mDetailButton.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		getSupportMenuInflater().inflate(R.menu.poi, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			this.finish();
			break;
		case R.id.goingto:
			showAlertDialog("tototot", "goto");
			break;
		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_go:

			Intent it = new Intent();
			it.putExtra("poiInfoParcelable", poiInfoParcelable);
			setResult(MainActivity.REQUEST_ROUTE_PLANNING, it);
			finish();
			
			break;

		case R.id.btn_detail:
			break;
		default:
			break;
		}
	}
}
